# 思考：发起请求的必备要素有哪些？
# ip地址
# 端口号：http/80 https/443
# 请求参数： request body（查询参数、json、form表单）  、request headers（token）
# 请求方式
# 接口地址
import uuid
import requests
from datetime import datetime
# response就是结果
# 登录
"""
uuid1 = str(uuid.uuid4()).split('-')[0]
response = requests.post(url="http://39.107.116.29:8899/adminapi/login",json={"account":"admin","pwd":"123456","imgcode":"11"})
# 打印结果
# print(response.json()) # json的方式返回，返回的形式是python原始对象：字典
# print(response.content) # 以二进制的方式返回
# print(response.text) # 以文本的方式返回，字符串
# print(response.url) # 打印以下请求的url
# print(response.headers) # 响应头
# print(response.status_code) # 响应状态码
# print(response.cookies) # 响应cookies
# 提取msg里的ok
msg = response.json()['msg']
token = response.json()['data']['token']
# print(msg)
assert msg == "ok"
assert response.status_code == 200
"""
# 添加用户分组
"""
start_time = datetime.now()
response1 = requests.post(url="http://39.107.116.29:8899/adminapi/user/user_group/save.html",json={"group_name":"赵政权" + uuid1},headers={"Authori-zation":f"Bearer {str(token)}"})
end_time = datetime.now()
# print(response1.json())
# 内置方法获取响应时间
# print(response1.elapsed.microseconds)
# 用datatime模块获取响应时间
# print(end_time-start_time)
# 响应头字符编码
# print(response1.encoding) # utf-8
"""
# 使用requests上传图片
url = "https://graph.baidu.com/upload"
files = {
    "image":("333.jpg",open(r"C:\Users\PC\Desktop\333.jpg","rb"),"image/jpeg")
}
r = requests.post(url,files=files)
print(r.json())


